<% extends 'public/base.html'%>
<% block content %>
  <div class="content whisper-content leacots-content layui-container">
    <div class="cont layui-row">
      <div class="whisper-list">
        <div class="item-box">
          <div class="review-version">
              <div class="form-box">
                <img class="banner-img" src="https://oss.zimu.website/zimu_file/liuyan.jpg?x-oss-process=style/blog_img">
                <div class="form">
                  <form class="layui-form">
                    <div class="layui-form-item layui-form-text">
                      <div class="layui-input-block">
                        <textarea name="desc" placeholder="既然来了，就说几句" class="layui-textarea" id="leacots_textarea"></textarea>
                      </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                      <div class="layui-inline">
                          <label class="layui-form-label">邮箱</label>
                          <div class="layui-input-inline">
                            <input type="tel" name="email" lay-verify="required|email" autocomplete="off" class="layui-input" id="email">
                          </div>
                        </div>
                        <div class="layui-inline">
                          <label class="layui-form-label">昵称</label>
                          <div class="layui-input-inline">
                            <input type="text" name="nickname" lay-verify="required" autocomplete="off" class="layui-input" id="nickname">
                          </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-input-block" style="text-align: right;">
                        <button class="layui-btn" lay-submit lay-filter="leactors_submit" type="button">立即提交</button>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
              <div class="volume">
                全部留言 <span><< msg_count >></span>
              </div>
              <div class="list-cont" id="msg_list">
              </div>
          </div>
        </div>
      </div>
      <div id="demo" style="text-align: center;"></div>
    </div>
  </div>
  <script type="text/html" id="laytplCont">
    <div class="cont">
      <div class="img">
        {{#  if(d.avatar){ }}
        <img src="{{d.avatar}}" alt="">
        {{#  } else { }}
        <img src="<< url_for('static', filename='img/header.png') >>" alt="">
        {{# } }}
      </div>
      <div class="text">
        <p class="tit"><span class="name">{{d.name}}</span><span class="data"><< now_date >></span></p>
        <p class="ct">{{d.cont}}</p>
      </div>
    </div>
  </script>
<% endblock %>
<% block script%>
      lp=laypage.render({
        elem: 'demo'
        ,count: << msg_count >> //数据总数，从服务端得到
          ,jump: function(obj, first){
            $.ajax({
              url:"<< url_for('main.get_leacots') >>",
              data:{page:obj.curr,limit:obj.limit},
              dataType:'json',
              success:function (res) {
                  if(res.status==0){
                    $('#msg_list').html('');
                    $.each(res.data,function(index,item){
                      var html_data='<div class="cont" data-id="'+item.Id+'"><div class="img"><img src="<< url_for('static', filename='img/header.png') >>" alt=""></div><div class="text"><p class="tit"><span class="name">'+item.nickname+'</span><span class="data">'+item.createTime+'</span></p><div class="ct">'+item.content+'</div></div></div>';
                    $('#msg_list').append(html_data);
                    });
                    obj.count=res.count;
                    var count = $('.list-cont .cont').length;
                    $('.volume span').text(count);
                  }
                  else{
                    layer.alert(res.msg)
                  }
              }
          })
         }
      });
      menu.init();
      form = layui.form;
      var leacots_textarea=layedit.build('leacots_textarea');
      form.on('submit(leactors_submit)', function(data){
            menu.submit(data.field.email,data.field.nickname,data.elem,leacots_textarea,"<< url_for('main.leacots') >>",function(){
            var count = $('.list-cont .cont').length;
                $('.volume span').text(parseInt(count)+1);
            });
			return false;
      });

<% endblock %>